cmake_minimum_required(VERSION 3.5)

project(Lamp VERSION 0.1 LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include_directories(
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_CURRENT_SOURCE_DIR}/S32K314DLP_LampCtrl/Logic
    ${CMAKE_CURRENT_SOURCE_DIR}/S32K314DLP_LampCtrl/Logic/View
    ${CMAKE_CURRENT_SOURCE_DIR}/S32K314DLP_LampCtrl/Logic/Snapshot
    ${CMAKE_CURRENT_SOURCE_DIR}/S32K314DLP_LampCtrl/Logic/StateMachine
    ${CMAKE_CURRENT_SOURCE_DIR}/S32K314DLP_LampCtrl/Logic/StateMachine/FrontLampStateMachine
    ${CMAKE_CURRENT_SOURCE_DIR}/S32K314DLP_LampCtrl/Logic/StateMachine/TurnLampStateMachine
    ${CMAKE_CURRENT_SOURCE_DIR}/S32K314DLP_LampCtrl/Interface
)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)

set(PROJECT_SOURCES
        main.cpp
        widget.cpp
        widget.h
        widget.ui
        S32K314DLP_LampCtrl/Logic/LampManager.h
        S32K314DLP_LampCtrl/Logic/LampManager.cpp
        S32K314DLP_LampCtrl/Logic/LampModel.h
        S32K314DLP_LampCtrl/Logic/LampModel.cpp
        S32K314DLP_LampCtrl/Logic/Animations.h
        S32K314DLP_LampCtrl/Logic/Animations.cpp
        S32K314DLP_LampCtrl/Logic/StateMachine/StateMachineState.h
        S32K314DLP_LampCtrl/Logic/StateMachine/StateMachineState.cpp
        S32K314DLP_LampCtrl/Logic/StateMachine/FrontLampStateMachine/FrontLampSleepState.h
        S32K314DLP_LampCtrl/Logic/StateMachine/FrontLampStateMachine/FrontLampSleepState.cpp
        S32K314DLP_LampCtrl/Logic/StateMachine/FrontLampStateMachine/FrontLampStateMachine.h
        S32K314DLP_LampCtrl/Logic/StateMachine/FrontLampStateMachine/FrontLampStateMachine.cpp
        S32K314DLP_LampCtrl/Logic/StateMachine/FrontLampStateMachine/FrontLampNormalState.h
        S32K314DLP_LampCtrl/Logic/StateMachine/FrontLampStateMachine/FrontLampNormalState.cpp
        S32K314DLP_LampCtrl/Logic/StateMachine/FrontLampStateMachine/FrontRibbonState.h
        S32K314DLP_LampCtrl/Logic/StateMachine/FrontLampStateMachine/FrontRibbonState.cpp
        S32K314DLP_LampCtrl/Logic/StateMachine/FrontLampStateMachine/FrontRibbonCtrlState.h
        S32K314DLP_LampCtrl/Logic/StateMachine/FrontLampStateMachine/FrontRibbonCtrlState.cpp
        S32K314DLP_LampCtrl/Logic/StateMachine/TurnLampStateMachine/TurnLampSleepState.h
        S32K314DLP_LampCtrl/Logic/StateMachine/TurnLampStateMachine/TurnLampSleepState.cpp
        S32K314DLP_LampCtrl/Logic/StateMachine/TurnLampStateMachine/TurnLampStateMachine.h
        S32K314DLP_LampCtrl/Logic/StateMachine/TurnLampStateMachine/TurnLampStateMachine.cpp
        S32K314DLP_LampCtrl/Logic/StateMachine/TurnLampStateMachine/TurnLampNormalState.h
        S32K314DLP_LampCtrl/Logic/StateMachine/TurnLampStateMachine/TurnLampNormalState.cpp
        S32K314DLP_LampCtrl/Logic/StateMachine/TurnLampStateMachine/RibbonLeTurnLampState.h
        S32K314DLP_LampCtrl/Logic/StateMachine/TurnLampStateMachine/RibbonLeTurnLampState.cpp
        S32K314DLP_LampCtrl/Logic/StateMachine/TurnLampStateMachine/RibbonPosnState.h
        S32K314DLP_LampCtrl/Logic/StateMachine/TurnLampStateMachine/RibbonPosnState.cpp
        S32K314DLP_LampCtrl/Logic/StateMachine/TurnLampStateMachine/RibbonPosnCtrlState.h
        S32K314DLP_LampCtrl/Logic/StateMachine/TurnLampStateMachine/RibbonPosnCtrlState.cpp
        S32K314DLP_LampCtrl/Logic/Snapshot/FrntTurnLampSnapshot.h
        S32K314DLP_LampCtrl/Logic/Snapshot/FrntTurnLampSnapshot.cpp
        S32K314DLP_LampCtrl/Interface/LowPwr.h
        S32K314DLP_LampCtrl/Interface/PlatformTypes.h
        S32K314DLP_LampCtrl/Interface/F3LampInterfaces.h
        S32K314DLP_LampCtrl/Interface/F3LampInterfaces.cpp
        S32K314DLP_LampCtrl/Logic/View/DayTimeAndPosLampView.h
        S32K314DLP_LampCtrl/Logic/View/DayTimeAndPosLampView.cpp
        S32K314DLP_LampCtrl/Logic/View/DlpModuleView.h
        S32K314DLP_LampCtrl/Logic/View/DlpModuleView.cpp
        S32K314DLP_LampCtrl/Logic/View/HiBeamView.h
        S32K314DLP_LampCtrl/Logic/View/HiBeamView.cpp
        S32K314DLP_LampCtrl/Logic/View/LeFrntTrunLampView.h
        S32K314DLP_LampCtrl/Logic/View/LeFrntTrunLampView.cpp
        S32K314DLP_LampCtrl/Logic/View/LoBeamView.h
        S32K314DLP_LampCtrl/Logic/View/LoBeamView.cpp
        S32K314DLP_LampCtrl/Logic/View/CornerLampView.h
        S32K314DLP_LampCtrl/Logic/View/CornerLampView.cpp
        S32K314DLP_LampCtrl/Logic/View/RibbonView.h
        S32K314DLP_LampCtrl/Logic/View/RibbonView.cpp
)

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(Lamp
        MANUAL_FINALIZATION
        ${PROJECT_SOURCES}
    )
# Define target properties for Android with Qt 6 as:
#    set_property(TARGET Lamp APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
#                 ${CMAKE_CURRENT_SOURCE_DIR}/android)
# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
else()
    if(ANDROID)
        add_library(Lamp SHARED
            ${PROJECT_SOURCES}
        )
# Define properties for Android with Qt 5 after find_package() calls as:
#    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
    else()
        add_executable(Lamp
            ${PROJECT_SOURCES}
        )
    endif()
endif()

target_link_libraries(Lamp PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)

# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
if(${QT_VERSION} VERSION_LESS 6.1.0)
  set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.Lamp)
endif()
set_target_properties(Lamp PROPERTIES
    ${BUNDLE_ID_OPTION}
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

include(GNUInstallDirs)
install(TARGETS Lamp
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(Lamp)
endif()
